#include <EditorModeManager.h>
#include <osg/Material>
#include <SceneViewer.h>
#include <SceneViewerFunctions.h>

EditorModeManager* EditorModeManager::_instance = NULL;
EditorModeManager::EditorModeManager()
{
	_editing_node = NULL;
	_temp_group_node = new osg::Group;
}
EditorModeManager::~EditorModeManager()
{

}

EditorModeManager* EditorModeManager::instance()
{
	if (_instance == NULL)
	{
		_instance = new EditorModeManager();
	}
	return _instance;

}


void EditorModeManager::setEditingNode( osg::ref_ptr<osg::Node> editing_node )
{
	_editing_node = editing_node;
}


void EditorModeManager::enterEditing()
{
	if (_editing_node == NULL)
	{
		return;
	}
	_scene_viewer_model_root = SceneViewer::instance()->getModelRoot();
	SceneViewer::instance()->removeChild(_scene_viewer_model_root.get());
	_temp_group_node = new osg::Group;
	_temp_group_node->addChild(_editing_node);
	SceneViewer::instance()->setModelRoot(_temp_group_node);
	SceneViewer::instance()->addChild(_temp_group_node);
}

void EditorModeManager::quitEditing()
{
	if (_editing_node == NULL)
	{
		return;
	}

	SceneViewer::instance()->removeChild(_temp_group_node);
	SceneViewer::instance()->addChild(_scene_viewer_model_root);
	SceneViewer::instance()->setModelRoot(_scene_viewer_model_root);
}


